class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int length = nums.size();
        unordered_map<int, int> findMap;
        // 重复的元素自动被后面一个替代
        for (int i = 0; i < length; i++) {
            int first = nums[i];
            int second = target - first;
            auto it = findMap.find(second);
            if (it != findMap.end() and it->second != i) {
                return {i, it->second};
            }
            findMap.insert({nums[i], i});
        }
        return {};
    }
};
